/**
 * Ext.ux.RegisterUserPanel
 * @author liuxl
 */
Ext.ux.RegisterUserPanel = function(){
	
       var desktop = MyDesktop.getDesktop();
        var win = desktop.getWindow('register_user_grid_win');
        if (!win) {
        	
            //定义一个 工具函数 来显示是否付费											
            var fuFeiRenderer = function(value){
                if (value == 1) {
                    return '<span style="color:red;font-weight:bold;">是</span>';
                }else {
                    return '<span style="color:green;font-weight:bold;">否</span>';
                }
            };
        	
            var sm = new Ext.grid.CheckboxSelectionModel();
            //定义一个JsonReader对象，用于表格列表数据显示，即grid对象
            var _jsonReader = null;

                _jsonReader = new Ext.data.JsonReader({
                    root: 'results'
                }, [{
                    name: 'usersId',
                    mapping: 'usersId'
                }, {
                    name: 'usersPhone',
                    mapping: 'usersPhone'
                }, {
                    name: 'createTime',
                    mapping: 'createTime'
                }]);
            
            var ds = null;

				ds = new Ext.data.Store({
                    proxy: new Ext.data.HttpProxy({
                        url: 'admin/registerUser.jhtml?method=userList'
                    }),
                    reader: _jsonReader
                });
            
          
			
            //定义列头信息
            var cm = null;

                cm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), sm, {
                    header: "用户编号",
                    width: 50,
                    sortable: true,
                    dataIndex: 'usersId'
                }, {
                    header: "手机号码",
                    width: 100,
                    sortable: true,
                    dataIndex: 'usersPhone'
                }, 
                 {
                    header: "注册时间",
                    width: 100,
                    dataIndex: 'createTime'
                }]);
            
                
                
                function showAddPanel(){
                    newwin = new Ext.Window({
                        xtype: 'window',
                        title: '添加注册用户信息',
                        buttonAlign: 'right',
                        closable: true,
                        layout: 'fit',
                        modal: 'true',
                        width: 623,
                        height: 263,
                        closeAction: 'hide',
                        plain: true,
                        items: [addForm]
                    
                    });
                    newwin.show();
                };
               
                function showFileAddPanel(){
                    // create the window on the first click and reuse on subsequent clicks
                    zip_newwin = new Ext.Window({
                        xtype: 'window',
                        title: '批量添加信息',
                        buttonAlign: 'right',
                        closable: true,
                        layout: 'fit',
                        modal: 'true',
                        width: 350,
                        height: 180,
                        closeAction: 'hide',
                        plain: true,
                        items: new Ext.TabPanel({
                            activeTab: 0,
                            width: 330,
                            height: 170,
                            defaults: {
                                bodyStyle: 'padding:2px'
                            },
                            xtype: 'tabpanel',
                            plain: true,
                            defaults: {
                                frame: true
                            },
                            closable: true,
                            items: [zip_addForm]
                        
                        })
                    
                    });
                    zip_newwin.show();
                };        
                var zip_addForm  = new Ext.FormPanel({
                    layout: 'form',
                    border: false,
                    labelSeparator: '：',
                    frame: true,
                    labelWidth: 80,
                    labelAlign: 'left',
                    buttonAlign: 'right',
                    bodyStyle: 'padding:5px',
                    width: 330,
                    fileUpload: true, //允许上传文件
                    items: [{
                     xtype: 'textfield',
                        inputType: 'file',
                        fieldLabel: 'zip文件',
                        name: 'file',
                        anchor: '96%'
                    
                    }
					],
                    buttons: [{
                        id: 'btnSave',
                        text: '保 存',
                        handler: function(){
                            if (zip_addForm.form.isValid())//客户端先验证数据
                            {
                            
                                //  this.disabled = true; //禁止保存按钮，防止多次提交
                                zip_addForm.form.doAction('submit', {
                                    url: '/admin/registerUser.jhtml?method=saveTxt',
                                    method: 'post',
                                    waitTitle: '请稍候',
                                    waitMsg: '正在提交表单数据，请稍候...',
                                    success: function(form, action){
                                        Ext.MessageBox.alert("提示", "上传成功");
                                        zip_addForm.form.reset();
                                        this.disabled = false;
                                        zip_newwin.hide();
                                      
                                    },
                                    failure: function(){
                                        Ext.MessageBox.alert("提示", "上传格式不正确");
                                        this.disabled = false;
                                    }
                                })
                            }
                        }
                        
                    }, {
                        text: '取 消',
                        handler: function(){
                            zip_newwin.hide();
                        }
                    }]
                });
            //开始创建Add面板
            var addForm = null;
            var userId = 0;   
            addForm = new Ext.FormPanel({
                layout: 'column',
                border: false,
                labelSeparator: '：',
                frame: true,
                labelWidth: 80,
                labelAlign: 'left',
                buttonAlign: 'right',
                bodyStyle: 'padding:5px',
                width: 600,
                fileUpload: true, //允许上传文件
                items: [{
                    layout: 'column',
                    items: [{
                        columnWidth: .5,
                        layout: 'form',
                        items: [{
                            xtype: 'textfield',
                            fieldLabel: '用户名',
                            name: 'usersName',
                            //width:200
							maxLength:50,
					        maxLengthText:'名称不能超过50个字符',
                            allowBlank: false,
                            blankText: '用户名不能为空！',
                            anchor: '96%'
                        }, {
                            xtype: 'textfield',
                            inputType: 'password',
                            fieldLabel: '密码',
                            id:'pass1',
                            name: 'usersPassword',
                            maxLength: 15,
                            maxLengthText: '密码长度不能超过15位!',
                            minLength: '6',
                            minLengthText: '密码长度不能少于6位!',
                            allowBlank: false,
                            blankText: '密码不能为空',
                            anchor: '96%'
                        },    {
                            xtype: 'textfield',
                            fieldLabel: '电子邮件',
                            name: 'usersEmail',
                            vtype: 'email',
                            emailText: 'email格式不正确!!',               
                            //width:200
                            anchor: '96%'
                        }, {
                            xtype: 'textarea',
                            fieldLabel: '描述',
                            name: 'usersDesc',
                            width: 200,
                            height: 100
                        
                        }]
                    }, {
                        columnWidth: .5,
                        layout: 'form',
                        items: [{
                            xtype: 'textfield',
                            fieldLabel: '移动电话',
                            name: 'usersPhone',
                            maxLength:50,
                            vtype: 'alphanum',
                            alphanumMask: '只能输入数字!!',
                            regex : /^1\d{10}$/,
                            regexText:"请输入正确的手机号码!",   
                            anchor: '96%'
                        
                        }, {
                            xtype: 'textfield',
                            inputType: 'password',
                            fieldLabel: '确认密码',
                            id:'pass2',
                            name: 'repassword',                              
                            maxLength: 15,
                            maxLengthText: '密码长度不能超过15位!',
                            minLength: '6',
                            minLengthText: '密码长度不能少于6位!',
                            allowBlank: false,
                            blankText: '密码不能为空',                                                                                            
                            invalidText: '两次密码不一致！',
                            validator: function() {
                            if (Ext.get('pass1').dom.value == Ext.get('pass2').dom.value) {
                             return true;
                            } else {
                              return false;
                              }
                            },
                             anchor: '96%'                              
                        }]
                    }]
                }],
                buttons: [{
                    id: 'btnSave',
                    text: '保 存',
                    handler: function(){
                        if (addForm.form.isValid())//客户端先验证数据
                        {
                        
                            // this.disabled = true; //禁止保存按钮，防止多次提交
                            var ok = "123";
                            addForm.form.doAction('submit', {
                                url: 'admin/registerUser.jhtml?method=saveUser',
                                method: 'post',
                                waitTitle: '请稍候',
                                waitMsg: '正在提交表单数据，请稍候...',
                                params: {
                                    tishi: ok
                                },
                                success: function(form, action){
                                	getAlertMessage("提示","操作成功!",Ext.MessageBox.WARNING);
                                    addForm.form.reset();
                                    this.disabled = false;
                                    newwin.hide();
                                    loadDs(ds,100);
                                },
                                failure: formError
                            })
                        }
                    }
                    
                }, {
                    text: '取 消',
                    handler: function(){
                        newwin.hide();
                    }
                }]
            });
           
            //创建表格
            var grid = null;
            /////////////////////////

                grid = new Ext.grid.GridPanel({
                    cm: cm,
                    sm: sm,
                    border: false,
                    loadMask: { // 加载数据时出险遮罩时状态条上呈现的等待信息
                        msg: "数据加载中，请稍等..."
                    },
                    store: ds,
                    viewConfig: {
                        forceFit: true // 自动调整每列的宽度
                    },
                    bbar: golbalBBar(ds,100),
                    tbar: [{
                        text: '增加',
                        tooltip: '增加一列',
                        iconCls: 'add',
                        handler: function(){
                            showAddPanel();
                        }
                    }, '-', {
                        text: '导入',
                        tooltip: '导入一Txt文档',
                        iconCls: 'add',
                        handler: function(){
                    	showFileAddPanel();
                        }
                    }]
                })
            
            //创建表格end
            //////////////////////////////////////////
            win = desktop.createWindow({
                id: 'register_user_grid_win',
                title: '注册用户管理',
                width: 740,
                height: 480,
                iconCls: 'icon-grid',
                shim: false,
                animCollapse: false,
                constrainHeader: true,
                
                layout: 'fit',
                items: grid
            
            });
             loadDs(ds,100);
        }
        win.show();
    }
